var fs = require("fs");
var turf = require("@turf/turf");
var booleanWithin = turf.booleanWithin;

var inFile = fs.readFileSync("output.json", "utf-8");

var inJson = JSON.parse(inFile);
console.log(inJson);

var polygon = turf.polygon([[[121.514141, 31.233789],
[121.539639, 31.233789],
[121.539639, 31.216995],
[121.514141, 31.216995],
[121.514141, 31.233789]]])
var outValues = {
    tiles: []
}

for (var key in inJson) {
    var value = inJson[key];

    var point = turf.point([value.ltLng, value.ltLat]);
    var point1 = turf.point([value.rbLng, value.rbLat]);


    if (turf.booleanWithin(point, polygon) || turf.booleanWithin(point1, polygon)) {
        outValues.tiles.push(key);
    }
}

console.log("所有瓦片：", outValues.tiles, "总长度：", outValues.tiles.length)

fs.writeFileSync("outtile.json", JSON.stringify(outValues), "utf-8");
